package com.briup.jdk8.day02;

import com.briup.corejava.day11.pojo.Student;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;

/**
 * 方法引用入门
 */
public class Test5 {
    public static void main(String[] args) {
        Runnable r1 = ()->{
            System.out.println("aaa");
        };
        // 使用Test5的静态方法test里的实现去替代run方法的实现
        // Runnable r2 = Test5::test;
        Consumer<String> c = Test5::test;
        c.accept("aaa");

        // 引用非静态成员方法
        Action a  = MethodHandler::test;
        String run = a.run(new MethodHandler(),
                1,
                Arrays.asList("2", "3"));
        System.out.println("run = " + run);

        // 引用Student中构造方法实现
        // 调用空参
        StudentFactory sf = Student::new;
        Student s1 = sf.get();
        // 调用全参
        StudentFactory2 sf2 = Student::new;
        Student s2 = sf2.get("张三", 20);
    }
    public static void test(String s){
        System.out.println(s);
    }
}
interface Action{
    String run(MethodHandler me, int i, List<String> list);
}
class MethodHandler{
    // 使用方法引用，完成对run的实现
    public String test(int i,List<String> list){
        return list.get(i);
    }

}
interface StudentFactory{
    Student get();
}
interface StudentFactory2{
    Student get(String name,Integer age);
}
